package com.ry.currentContainer;

import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

//并发容器    读多写少场景  读写分离  最终一致性  写入开辟空间，避免并发修改
public class CopyOnWriteArrayListExp {
    public static void main(String[] args) {

        CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>(new Integer[]{1,2,3});

        System.out.println(list);

        Iterator<Integer> itr1 = list.iterator();

        list.add(4);

        System.out.println(list);

        Iterator<Integer> itr2 = list.iterator();

        itr1.forEachRemaining(System.out::println);

        itr2.forEachRemaining(System.out::println);


    }
}
